<?php
class mod_blog extends xmldb{
	public $total, $pagecnt, $pagenum, $pagestart, $pageend;
	
	public function getblogs($page=1, $psize=20){
		$blogs = array();
		foreach($this->xml->children() as $blog){
			$blogs[] = (array)$blog;
		}
		$this->total = count($blogs);
		$this->pagecnt = ceil($this->total/$psize);
		$this->pagenum = (int)$page;
		if($this->pagenum < 1) $this->pagenum = 1;
		if($this->pagenum > $this->pagecnt) $this->pagenum = $this->pagecnt;
		
		$this->pagestart = $this->pagenum - 5;
		if($this->pagestart < 1) $this->pagestart = 1;
		$this->pageend = $this->pagestart + 10;
		if($this->pageend > $this->pagecnt) $this->pageend = $this->pagecnt;
		
		return array_slice($blogs, ($this->pagenum-1)*$psize, $psize, true);
	}
}
?>
